package com.bot.dev.module.job.task;

import com.bot.common.timer.CommonTimerTaskRunner;
import com.bot.nft.core.enums.op.AirdropEnum;
import com.bot.nft.module.op.domain.OpAirInfo;
import com.bot.nft.module.op.service.IOpAirInfoService;
import com.bot.nft.module.op.service.IOpAirListService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 特殊空投定时器定时器
 *
 * @author zhangkaige
 * @date 2024/1/30 15:52
 **/
@Slf4j
@Component
public class AirdropTimerTaskRunner implements CommonTimerTaskRunner {

    @Resource
    private IOpAirInfoService iOpAirInfoService;
    private int n = 1;

    @Override
    public void action() {
        log.info("我是一个定时任务，正在在被执行第" + n + "次");
        n = n + 1;

        //普特空投和特殊空投中未指定时间的空投
        List<OpAirInfo> opAirInfos = iOpAirInfoService.airInfoList(AirdropEnum.SNAPSHOT_STATUS.getValue(), null);
        for (OpAirInfo opAirInfo : opAirInfos) {
            Date exeTime = opAirInfo.getExeTime();
            if (exeTime.after(new Date())) {
                iOpAirInfoService.exeAirdrop(opAirInfo.getId());
            }
        }

        //特殊空投中指定时间的空投
        List<OpAirInfo> speAirInfos = iOpAirInfoService.airInfoList(AirdropEnum.ONGOING_STATUS.getValue(),
                AirdropEnum.LIST_CONDITION.getValue());
        for (OpAirInfo opAirInfo : speAirInfos) {
            iOpAirInfoService.exeAirdrop(opAirInfo.getId());

        }


    }
}
